
Imports System.Diagnostics.Process
Imports System.Threading
Public Class F_Attendance

    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Public Sub Attendance_bind(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)

            oEdit = oform.Items.Item("15").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("6").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("8").Specific
            oEdit.String = "Open"
            oEdit = oform.Items.Item("11").Specific
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("17").Specific
            oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()

            oform.DataBrowser.BrowseBy = "4"
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Attendance_Ticks_bind(ByVal oform As SAPbouiCOM.Form)
        Try

            oDBDataSource = oform.DataSources.DBDataSources.Add("@AI_ATTENDANCE")
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_DATE)
            'oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            'oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.DataTables.Add("@AI_ATTENDANCE")
            oEdit = oform.Items.Item("15").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oMatrix = oform.Items.Item("5").Specific
            oColumns = oMatrix.Columns
            'oColumn = oColumns.Item("V_2")
            'oColumn.DataBind.SetBound(True, "@AI_ATTENDANCE", "U_AI_PetCode")
            'oColumn = oColumns.Item("V_1")
            'oColumn.DataBind.SetBound(True, "@AI_ATTENDANCE", "U_AI_PetName")
            oColumn = oColumns.Item("V_0")
            oColumn.DataBind.SetBound(True, "", "oedit4")
            oMatrix.AddRow()
            oCombo = oMatrix.Columns.Item("V_0").Cells.Item(oMatrix.RowCount).Specific
            oCombo.ValidValues.Add("Yes", "Yes")
            oCombo.ValidValues.Add("No", "No")
            'oMatrix.Clear()
            'oMatrix.AutoResizeColumns()
            'oDBDataSource.Query()
            'oMatrix.LoadFromDataSource()

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Attendance_bind_DogInv(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)

            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit5", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit6", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit7", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit8", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            'oCombo = oform.Items.Item("18").Specific
            'oCombo.DataBind.SetBound(True, "", "oedit5")
            'oCombo.ValidValues.Add("Yes", "Y")
            'oCombo.ValidValues.Add("No", "N")
            'oCombo.Select("Y", SAPbouiCOM.BoSearchKey.psk_ByDescription)
            'oCombo = oform.Items.Item("12").Specific
            'oCombo.DataBind.SetBound(True, "", "oedit6")
            'oCombo.ValidValues.Add("Yes", "Y")
            'oCombo.ValidValues.Add("No", "N")
            'oCombo.Select("Y", SAPbouiCOM.BoSearchKey.psk_ByDescription)
            'oCombo = oform.Items.Item("14").Specific
            'oCombo.DataBind.SetBound(True, "", "oedit7")
            'oCombo.ValidValues.Add("Yes", "Y")
            'oCombo.ValidValues.Add("No", "N")
            'oCombo.Select("Y", SAPbouiCOM.BoSearchKey.psk_ByDescription)
            'oCombo = oform.Items.Item("16").Specific
            'oCombo.DataBind.SetBound(True, "", "oedit8")
            'oCombo.ValidValues.Add("Yes", "Y")
            'oCombo.ValidValues.Add("No", "N")
            'oCombo.Select("Y", SAPbouiCOM.BoSearchKey.psk_ByDescription)

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Attendance_bind_AttenReport(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)
            CFL_BP_PetMaster1(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            'oEdit = oform.Items.Item("6").Specific
            'oEdit.DataBind.SetBound(True, "", "oedit2")
            'oEdit.ChooseFromListUID = "CFLPM1"
            'oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub AnnualPackge_Report(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_Customer(oform, SBO_Application)
            CFL_BP_PetMaster1(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit5", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLBPC"
            oEdit.ChooseFromListAlias = "CardCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oCombo = oform.Items.Item("130").Specific
            oCombo.ValidValues.Add("Show Negative Only", "1")
            oCombo.ValidValues.Add("Show All", "2")
            oCombo.Select("2", SAPbouiCOM.BoSearchKey.psk_ByDescription)
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub LastAttendance_bind_AttenReport(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)
            CFL_BP_PetMaster1(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)

            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            'oEdit = oform.Items.Item("6").Specific
            'oEdit.DataBind.SetBound(True, "", "oedit2")
            'oEdit.ChooseFromListUID = "CFLPM1"
            'oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")


        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Attendance_bind_DayPassReport(ByVal oform As SAPbouiCOM.Form)
        Try
            'CFL_BP_PetMaster(oform, SBO_Application)
            'CFL_BP_PetMaster1(oform, SBO_Application)
            'CFL_BP_Customer1(oform, SBO_Application)
            CFL_BP_Customer(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_SHORT_NUMBER)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_SHORT_NUMBER)
            oform.DataSources.UserDataSources.Add("oedit5", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            'oform.DataSources.UserDataSources.Add("oedit6", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            'oEdit = oform.Items.Item("4").Specific
            'oEdit.DataBind.SetBound(True, "", "oedit1")
            'oEdit.ChooseFromListUID = "CFLPM"
            'oEdit.ChooseFromListAlias = "U_PetCode"
            'oEdit = oform.Items.Item("6").Specific
            'oEdit.DataBind.SetBound(True, "", "oedit2")
            'oEdit.ChooseFromListUID = "CFLPM1"
            'oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit = oform.Items.Item("12").Specific
            oEdit.DataBind.SetBound(True, "", "oedit5")
            oEdit.ChooseFromListUID = "CFLBPC"
            oEdit.ChooseFromListAlias = "CardCode"
            'oEdit = oform.Items.Item("14").Specific
            'oEdit.DataBind.SetBound(True, "", "oedit6")
            'oEdit.ChooseFromListUID = "CFLBPC2"
            'oEdit.ChooseFromListAlias = "CardCode"


        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
        Try

            If pVal.FormUID = "AI_TICKS" And pVal.ItemUID = "6" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Try
                    oForm = SBO_Application.Forms.Item("AI_TICKS")
                    Dim i As Integer
                    Dim petcode As String = ""
                    Dim Tick As String = ""
                    oForm = SBO_Application.Forms.Item("AI_TICKS")
                    For i = 1 To oMatrix.RowCount
                        oEdit = oMatrix.Columns.Item("V_2").Cells.Item(i).Specific
                        petcode = oEdit.String
                        Try
                            'oMatrix = oForm.Items.Item("5").Specific
                            'oColumns = oMatrix.Columns
                            oCombo = oMatrix.Columns.Item("V_0").Cells.Item(i).Specific
                            Tick = oCombo.Selected.Value
                        Catch ex As Exception
                        End Try
                        oEdit = oForm.Items.Item("15").Specific
                        Dim dt As String = oEdit.Value
                        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                        oRecordSet.DoQuery("Update [@AI_ATTENDANCE] set U_AI_TickHealth='" & Tick & "' where U_AI_PetCode='" & petcode & "' and U_AI_Date='" & dt & "' ")

                    Next
                    oMatrix.Clear()

                Catch ex As Exception

                End Try
            End If
            If pVal.FormUID = "AI_TICKS" And pVal.ItemUID = "Show" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Try
                    oForm = SBO_Application.Forms.Item("AI_TICKS")

                    oEdit = oForm.Items.Item("15").Specific
                    If oEdit.String = "" Then
                        SBO_Application.StatusBar.SetText("Plz Enter Attendance Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                        BubbleEvent = False
                        Exit Sub
                    End If

                    Dim sqlstr As String = "SELECT T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_TickHealth] FROM [dbo].[@AI_ATTENDANCE]  T0 WHERE T0.[U_AI_Date] ='" & oEdit.Value & "' and T0.[U_AI_TickHealth] is null "
                    oForm.DataSources.DataTables.Item("@AI_ATTENDANCE").ExecuteQuery(sqlstr)
                    oMatrix = oForm.Items.Item("5").Specific
                    oMatrix.Clear()
                    oColumns = oMatrix.Columns

                    oForm.Items.Item("5").Specific.Columns.item("V_2").DataBind.Bind("@AI_ATTENDANCE", "U_AI_PetCode")
                    oForm.Items.Item("5").Specific.Columns.item("V_1").DataBind.Bind("@AI_ATTENDANCE", "U_AI_PetName")
                    'oForm.Items.Item("5").Specific.Columns.item("V_0").DataBind.Bind("@AI_ATTENDANCE", "U_AI_TickHealth")
                    'oCombo = oMatrix.Columns.Item("V_0").Cells.Item("").Specific
                    'oCombo.ValidValues.Add("Yes", "Yes")
                    'oCombo.ValidValues.Add("No", "No")

                    oForm.Items.Item("5").Specific.LoadFromDataSource()
                    oMatrix.LoadFromDataSource()
                    oForm.Items.Item("5").Specific.AutoResizeColumns()
                Catch ex As Exception

                End Try

            End If
            If pVal.FormUID = "DayPassBalanceReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                'DayPassBalanceReport


                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf DayPassBalanceReport)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If
            '----------------
            '----------------
            If pVal.FormUID = "DayPassBalanceReport" Then
                oForm = SBO_Application.Forms.Item("DayPassBalanceReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then
                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "12" Then
                                Try
                                    oEdit = oForm.Items.Item("12").Specific
                                    oEdit.String = oDataTable.GetValue("CardCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "14" Then
                                Try
                                    oEdit = oForm.Items.Item("14").Specific
                                    oEdit.String = oDataTable.GetValue("CardCode", 0)
                                Catch ex As Exception
                                End Try
                            End If

                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------
            '**********************************
            If pVal.FormUID = "LastAttendanceReport" Then
                oForm = SBO_Application.Forms.Item("LastAttendanceReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------
            If pVal.FormUID = "LastAttendanceReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf LastAttendance)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
                'LastAttendance
            End If
            '**************************************
            '----------------------
            If pVal.FormUID = "AttendanceReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf AttendanceReport)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '----------------------
            If pVal.FormUID = "AnnualReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf AnnualPackageReport)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '**********************************
            If pVal.FormUID = "AnnualReport" Then
                oForm = SBO_Application.Forms.Item("AnnualReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("CardCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '----------------
            If pVal.FormUID = "AttendanceReport" Then
                oForm = SBO_Application.Forms.Item("AttendanceReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------

            '------------
            If pVal.FormUID = "DogInventoryReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                'DogInventory_Report  
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf DogInventory_Report)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If
            '----------------
            If pVal.FormUID = "DogInventoryReport" Then
                oForm = SBO_Application.Forms.Item("DogInventoryReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            'If pVal.FormUID = "AI_ATTENDANCE" And pVal.FormMode = SAPbouiCOM.BoFormMode.fm_OK_MODE Then
            '    Try
            '        oForm = SBO_Application.Forms.Item("AI_ATTENDANCE")
            '        oItem = oForm.Items.Item("102")
            '        ' If oItem.Enabled = True Then
            '        oChk1 = oForm.Items.Item("102").Specific
            '        If oChk1.Checked = True Then
            '            oItem.Enabled = False
            '        Else
            '            oItem.Enabled = True
            '        End If
            '        'End If

            '        '--------------------
            '        oChk1 = oForm.Items.Item("66").Specific
            '        oChk2 = oForm.Items.Item("68").Specific
            '        If oChk1.Checked = True Or oChk2.Checked = True Then
            '            oItem = oForm.Items.Item("66")
            '            oItem.Enabled = False
            '            oItem = oForm.Items.Item("68")
            '            oItem.Enabled = False
            '        Else
            '            oItem = oForm.Items.Item("66")
            '            oItem.Enabled = True
            '            oItem = oForm.Items.Item("68")
            '            oItem.Enabled = True
            '        End If

            '        '--------------------
            '        oChk1 = oForm.Items.Item("67").Specific
            '        oChk2 = oForm.Items.Item("69").Specific
            '        If oChk1.Checked = True Or oChk2.Checked = True Then
            '            oItem = oForm.Items.Item("67")
            '            oItem.Enabled = False
            '            oItem = oForm.Items.Item("69")
            '            oItem.Enabled = False
            '        Else
            '            oItem = oForm.Items.Item("67")
            '            oItem.Enabled = True
            '            oItem = oForm.Items.Item("69")
            '            oItem.Enabled = True
            '        End If
            '    Catch ex As Exception

            '    End Try
            'End If
            'puni
            '--------------------
            '--------------End dog inv
            'Choose From List
            Try 'puni
                Try
                    If pVal.FormUID = "AI_ATTENDANCE" And pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                        oItem = oForm.Items.Item("102")
                        oItem.Enabled = True
                        oItem = oForm.Items.Item("66")
                        oItem.Enabled = True
                        oItem = oForm.Items.Item("67")
                        oItem.Enabled = True
                        oItem = oForm.Items.Item("68")
                        oItem.Enabled = True
                        oItem = oForm.Items.Item("69")
                        oItem.Enabled = True
                    End If
                    If pVal.FormUID = "AI_ATTENDANCE" And pVal.FormMode <> SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                        oEdit = oForm.Items.Item("4").Specific
                        Dim Sqlstr As String = "SELECT T0.[U_Ignore],T0.[U_AI_Pickup], T0.[U_AI_Dropoff], T0.[U_AI_CheckIn], T0.[U_AI_CheckOut] FROM [dbo].[@AI_ATTENDANCE]  T0 WHERE T0.[DocNum] ='" & oEdit.String & " '"
                        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                        oRecordSet.DoQuery(Sqlstr)

                        oItem = oForm.Items.Item("102")
                        oChk1 = oForm.Items.Item("102").Specific
                        If oRecordSet.Fields.Item("U_Ignore").Value = "Y" Then
                            oItem.Enabled = False
                        Else
                            oItem.Enabled = True
                        End If
                        oItem = oForm.Items.Item("66")
                        'If oRecordSet.Fields.Item("U_AI_Pickup").Value = "Y" Then

                        'End If
                        oChk1 = oForm.Items.Item("66").Specific
                        If oRecordSet.Fields.Item("U_AI_Pickup").Value = "Y" Then
                            oItem.Enabled = False
                        Else
                            oItem.Enabled = True
                        End If
                        oItem = oForm.Items.Item("67")
                        oChk1 = oForm.Items.Item("67").Specific
                        If oRecordSet.Fields.Item("U_AI_Dropoff").Value = "Y" Then
                            oItem.Enabled = False
                        Else
                            oItem.Enabled = True
                        End If
                        oItem = oForm.Items.Item("68")
                        oChk1 = oForm.Items.Item("68").Specific
                        If oRecordSet.Fields.Item("U_AI_CheckIn").Value = "Y" Then
                            oItem.Enabled = False
                        Else
                            oItem.Enabled = True
                        End If
                        oItem = oForm.Items.Item("69")
                        oChk1 = oForm.Items.Item("69").Specific
                        If oRecordSet.Fields.Item("U_AI_CheckOut").Value = "Y" Then
                            oItem.Enabled = False
                        Else
                            oItem.Enabled = True
                        End If
                    End If
                Catch ex As Exception
                End Try

                If ((pVal.FormUID = "AI_ATTENDANCE" And pVal.InnerEvent = False And pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE And pVal.ItemUID = "11" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE) And (pVal.Before_Action = False)) Then
                    Try
                        oForm = SBO_Application.Forms.Item("AI_ATTENDANCE")
                        oEdit = oForm.Items.Item("11").Specific
                        Dim petcode As String = oEdit.String
                        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                        oRecordSet.DoQuery("SELECT T0.[U_AI_Walk], T0.[U_AI_Swim], T0.[U_AI_Lunch], T0.[U_AI_Medicine], T0.[U_AI_Breakfast], T0.[U_AI_Brunch], T0.[U_AI_AftTea], T0.[U_AI_Dinner], T0.[U_AI_Training], T0.[U_AI_LifeJack],T0.[U_AI_SpecAttn], T0.[U_AI_Instruct] FROM [dbo].[@AI_PETMASTER]  T0 WHERE T0.[U_PetCode] ='" & petcode & "'")
                        Try
                            oCombo = oForm.Items.Item("23").Specific
                            oCombo.Select(oRecordSet.Fields.Item(0).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        Try
                            oCombo = oForm.Items.Item("25").Specific
                            oCombo.Select(oRecordSet.Fields.Item(1).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        Try
                            oCombo = oForm.Items.Item("33").Specific
                            oCombo.Select(oRecordSet.Fields.Item(2).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        oEdit = oForm.Items.Item("1000005").Specific
                        oEdit.String = oRecordSet.Fields.Item(3).Value
                        Try
                            oCombo = oForm.Items.Item("29").Specific
                            oCombo.Select(oRecordSet.Fields.Item(4).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        Try
                            oCombo = oForm.Items.Item("31").Specific
                            oCombo.Select(oRecordSet.Fields.Item(5).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        Try
                            oCombo = oForm.Items.Item("35").Specific
                            oCombo.Select(oRecordSet.Fields.Item(6).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        Try
                            oCombo = oForm.Items.Item("37").Specific
                            oCombo.Select(oRecordSet.Fields.Item(7).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try
                        oEdit = oForm.Items.Item("1000006").Specific
                        oEdit.String = oRecordSet.Fields.Item(8).Value
                        Try
                            oCombo = oForm.Items.Item("77").Specific
                            oCombo.Select(oRecordSet.Fields.Item(9).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
                        Catch ex As Exception
                        End Try

                    Catch ex As Exception

                    End Try
                    oEdit = oForm.Items.Item("57").Specific
                    oEdit.String = oRecordSet.Fields.Item(10).Value
                    oEdit = oForm.Items.Item("55").Specific
                    oEdit.String = oRecordSet.Fields.Item(11).Value

                End If
                If pVal.FormUID = "AI_ATTENDANCE" Then
                    oForm = SBO_Application.Forms.Item("AI_ATTENDANCE")
                    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                        Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                        oCFLEvento = pVal
                        Dim sCFL_ID As String
                        sCFL_ID = oCFLEvento.ChooseFromListUID
                        oForm = SBO_Application.Forms.Item(FormUID)
                        Dim oCFL As SAPbouiCOM.ChooseFromList
                        oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                        Try
                            If oCFLEvento.BeforeAction = False Then
                                Dim oDataTable As SAPbouiCOM.DataTable
                                oDataTable = oCFLEvento.SelectedObjects
                                If pVal.ItemUID = "11" Then
                                    oEdit = oForm.Items.Item("13").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetName", 0)
                                    Try
                                        oEdit = oForm.Items.Item("11").Specific
                                        oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                    Catch ex As Exception
                                    End Try
                                End If

                            End If
                        Catch ex As Exception
                            '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                        End Try
                    End If
                End If
                '--------------------
            Catch ex As Exception
            End Try
            '======================================================
            Try
                '-------------------End Choose From List-----------
                If pVal.FormUID = "AI_ATTENDANCE" And pVal.InnerEvent = False Then
                    oForm = SBO_Application.Forms.Item("AI_ATTENDANCE")
                    If pVal.Before_Action = False Then
                        Select Case pVal.EventType
                            Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                                If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                    If pVal.ItemUID = "1" Then
                                        oEdit = oForm.Items.Item("15").Specific
                                        oEdit.String = Format(Now.Date, "dd/MM/yy")
                                        oEdit = oForm.Items.Item("6").Specific
                                        oEdit.String = Format(Now.Date, "dd/MM/yy")
                                        oEdit = oForm.Items.Item("8").Specific
                                        oEdit.String = "Open"
                                        oEdit = oForm.Items.Item("17").Specific
                                        oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                    End If
                                End If


                            Case SAPbouiCOM.BoEventTypes.et_VALIDATE
                                If pVal.ItemUID = "17" Then
                                    oEdit = oForm.Items.Item("17").Specific
                                    If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                        SBO_Application.StatusBar.SetText("TimeIn Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        oEdit.Active = True
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                End If

                                If pVal.ItemUID = "91" Then
                                    oEdit = oForm.Items.Item("91").Specific
                                    If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                        SBO_Application.StatusBar.SetText("TimeOut Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        oEdit.Active = True
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("87").Specific
                                    Dim st As Date = oEdit.Value
                                    oEdit = oForm.Items.Item("91").Specific
                                    If oEdit.String = "" Then
                                        Exit Sub
                                    End If
                                    If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                        SBO_Application.StatusBar.SetText("TimeOut Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        oEdit.Active = True
                                        BubbleEvent = False
                                        Exit Sub
                                    End If

                                    Dim Et As Date = oEdit.Value
                                    Dim Diffr As Date = Et.AddHours(-st.Hour)
                                    Diffr = Diffr.AddMinutes(-st.Minute)
                                    '' Dim Diff As String = Et - st
                                    'Dim k As String = ""
                                    'If Diff.Length = 1 Then
                                    '    k = "00:0" & Diff
                                    'ElseIf Diff.Length = 2 Then
                                    '    k = "00:" & Diff
                                    'ElseIf Diff.Length = 3 Then
                                    '    k = "0" & Diff.Substring(0, 1) & ":" & Diff.Substring(1, 2)
                                    'ElseIf Diff.Length = 4 Then
                                    '    k = Diff.Substring(0, 2) & ":" & Diff.Substring(2, 2)
                                    'End If
                                    oEdit = oForm.Items.Item("63").Specific
                                    oEdit.String = Diffr.Hour & ":" & Diffr.Minute
                                    'oEdit = oForm.Items.Item("8").Specific
                                    'oEdit.String = "Open"

                                End If

                            Case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT
                                'If pVal.ItemUID = "21" Then
                                '    oCombo = oForm.Items.Item("21").Specific
                                '    oEdit = oForm.Items.Item("19").Specific
                                '    oEdit.String = oCombo.Selected.Description
                                'End If

                        End Select
                    ElseIf pVal.Before_Action = True Then
                        Select Case pVal.EventType
                            Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                                If pVal.ItemUID = "64" Then
                                    oEdit = oForm.Items.Item("17").Specific
                                    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                    oEdit = oForm.Items.Item("87").Specific
                                    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                End If
                                If pVal.ItemUID = "65" Then
                                    oEdit = oForm.Items.Item("19").Specific
                                    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                    oEdit = oForm.Items.Item("91").Specific
                                    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                End If
                                If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then

                                    'If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then

                                    '  End If

                                    If pVal.ItemUID = "1" Then

                                        oEdit = oForm.Items.Item("11").Specific
                                        If oEdit.String = "" Then
                                            SBO_Application.StatusBar.SetText("Select Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("15").Specific
                                        If oEdit.String = "" Then
                                            SBO_Application.StatusBar.SetText("Select Attendance Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("6").Specific
                                        If oEdit.String = "" Then
                                            SBO_Application.StatusBar.SetText("Select Document Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("17").Specific
                                        If oEdit.String = "" Then
                                            SBO_Application.StatusBar.SetText("Select Time In", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("17").Specific
                                        If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                            SBO_Application.StatusBar.SetText("TimeIn Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("19").Specific
                                        If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                            SBO_Application.StatusBar.SetText("TimeOut Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("87").Specific
                                        If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                            SBO_Application.StatusBar.SetText("Day Care Time In Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        oEdit = oForm.Items.Item("91").Specific
                                        If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                            SBO_Application.StatusBar.SetText("Day Care TimeOut Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        Dim PickUp As String = ""
                                        Dim Dropoff As String = ""
                                        Dim CheckIn As String = ""
                                        Dim CheckOut As String = ""
                                        oCheck = oForm.Items.Item("66").Specific
                                        If oCheck.Checked = True Then
                                            PickUp = "Y"
                                        End If
                                        oCheck = oForm.Items.Item("68").Specific
                                        If oCheck.Checked = True Then
                                            CheckIn = "Y"
                                        End If


                                        oCheck = oForm.Items.Item("67").Specific
                                        If oCheck.Checked = True Then
                                            Dropoff = "Y"
                                        End If
                                        oCheck = oForm.Items.Item("69").Specific
                                        If oCheck.Checked = True Then
                                            CheckOut = "Y"
                                        End If

                                        If PickUp = "" And CheckIn = "" Then
                                            SBO_Application.StatusBar.SetText("Please Tick PickUp or CheckIn", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        ''If Dropoff = "" And CheckOut = "" Then
                                        ''    SBO_Application.StatusBar.SetText("Please Tick Dropoff or CheckOut", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        ''    oEdit.Active = True
                                        ''    BubbleEvent = False
                                        ''    Exit Sub
                                        ''End If
                                        If PickUp = "Y" And CheckIn = "Y" Then
                                            SBO_Application.StatusBar.SetText("Both PickUp or CheckIn can't Tick", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        If Dropoff = "Y" And CheckOut = "Y" Then
                                            SBO_Application.StatusBar.SetText("Both Dropoff or CheckOut can't Tick", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            oEdit.Active = True
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                        If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                            Try
                                                oEdit = oForm.Items.Item("15").Specific
                                                Dim dt As String = oEdit.Value
                                                oEdit = oForm.Items.Item("11").Specific

                                                oRecordSet5 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                                oRecordSet5.DoQuery("SELECT T0.[U_AI_PetCode] FROM [dbo].[@AI_ATTENDANCE]  T0 WHERE T0.[U_AI_PetCode] ='" & oEdit.String & "' and  T0.[U_AI_Date] ='" & dt & "'")
                                                If oRecordSet5.RecordCount > 0 Then
                                                    SBO_Application.StatusBar.SetText("This Dog Alreadyalready Pick UP or Check In Today", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                                    BubbleEvent = False
                                                    Exit Sub
                                                End If

                                            Catch ex As Exception

                                            End Try
                                            Try
                                                If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                                    Dim oGeneralService1 As SAPbobsCOM.GeneralService
                                                    Dim oGeneralData1 As SAPbobsCOM.GeneralData
                                                    Dim oSons1 As SAPbobsCOM.GeneralDataCollection
                                                    Dim oSon1 As SAPbobsCOM.GeneralData
                                                    Dim sCmp1 As SAPbobsCOM.CompanyService
                                                    sCmp1 = Ocompany.GetCompanyService
                                                    oGeneralService1 = sCmp1.GetGeneralService("AI_ACTPORCESS")
                                                    oGeneralData1 = oGeneralService1.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData)
                                                    oEdit = oForm.Items.Item("11").Specific
                                                    oGeneralData1.SetProperty("U_AI_PetCode", oEdit.String)
                                                    oEdit = oForm.Items.Item("13").Specific
                                                    oGeneralData1.SetProperty("U_AI_PetName", oEdit.String)
                                                    oEdit = oForm.Items.Item("15").Specific
                                                    Dim dt1 As Date = ParamDate(oEdit.String)
                                                    oGeneralData1.SetProperty("U_AI_ActDt", dt1.Date)
                                                    oGeneralData1.SetProperty("U_AI_ActCode", "1stTick")
                                                    oGeneralData1.SetProperty("U_AI_ActName", "1stTick")
                                                    oGeneralService1.Add(oGeneralData1)
                                                End If
                                            Catch ex As Exception
                                            End Try
                                        End If
                                        If (pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) Then
                                            Try
                                                oEdit = oForm.Items.Item("91").Specific
                                                Dim TOut As String = oEdit.String.Replace(":", "")
                                                Dim Tout2 As Integer = TOut
                                                If Tout2 = 93 Then
                                                    Tout2 = 930
                                                End If
                                                If Tout2 <= 930 Then
                                                    oChk1 = oForm.Items.Item("102").Specific
                                                    oChk1.Checked = True
                                                End If
                                            Catch ex As Exception

                                            End Try
                                        End If
                                        If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then


                                            'oEdit = oForm.Items.Item("15").Specific
                                            'Dim dt1 As String = oEdit.Value
                                            'oEdit = oForm.Items.Item("11").Specific
                                            ''Dim oRecordSetPC As SAPbobsCOM.Recordset
                                            'Dim BPCOde As String = OwnerCode(oEdit.String, Ocompany)
                                            'oRecordSetPC = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                            'oRecordSetPC.DoQuery("SELECT Distinct T1.[U_AI_CustCode],T0.[U_AI_PetCode] FROM [dbo].[@AI_ATTENDANCE]  T0 left join[dbo].[@AI_PETMASTER]  T1 on  T1.[U_PetCode] = T0.[U_AI_PetCode] WHERE T1.[U_AI_CustCode] ='" & BPCOde & "' and  T0.[U_AI_Date] ='" & dt1 & "'")
                                            'If oRecordSetPC.RecordCount = 0 Then
                                            TansportUpdate(PickUp, Dropoff)
                                            ' End If
                                            oChk1 = oForm.Items.Item("102").Specific
                                            If oChk1.Checked = False Then
                                                DayPassUpdate()
                                            End If
                                        End If
                                        If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Then
                                            oItem = oForm.Items.Item("102")
                                            If oItem.Enabled = True Then
                                                oChk1 = oForm.Items.Item("102").Specific
                                                If oChk1.Checked = True Then
                                                    DayPassUpdate_UpdateMode()
                                                End If
                                            End If


                                            'oEdit = oForm.Items.Item("15").Specific
                                            'Dim dt11 As String = oEdit.Value
                                            'oEdit = oForm.Items.Item("11").Specific
                                            'Dim oRecordSetPC1 As SAPbobsCOM.Recordset
                                            'Dim BPCOde1 As String = OwnerCode(oEdit.String, Ocompany)
                                            'oRecordSetPC1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                            'oRecordSetPC1.DoQuery("SELECT distinct T1.[U_AI_CustCode],T0.[U_AI_PetCode] FROM [dbo].[@AI_ATTENDANCE]  T0 left join[dbo].[@AI_PETMASTER]  T1 on  T1.[U_PetCode] = T0.[U_AI_PetCode] WHERE T1.[U_AI_CustCode] ='" & BPCOde1 & "' and  T0.[U_AI_Date] ='" & dt11 & "' and T0.[U_AI_Dropoff]='Y'")
                                            'If oRecordSetPC1.RecordCount = 0 Then
                                            PickUp = ""
                                            oItem = oForm.Items.Item("67")
                                            If oItem.Enabled = True Then
                                                oCheck = oForm.Items.Item("67").Specific
                                                If oCheck.Checked = True Then
                                                    Dropoff = "Y"
                                                End If
                                            Else
                                                Dropoff = ""
                                            End If
                                            TansportUpdate(PickUp, Dropoff)
                                            ' End If

                                        End If
                                        'Try
                                        '    If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                        '        TansportUpdate(PickUp, Dropoff)

                                        '        Try
                                        '            oEdit = oForm.Items.Item("63").Specific
                                        '            Dim diff As String = oEdit.String
                                        '            Dim diff1 As String = diff.Substring(3, 2)
                                        '            diff = diff.Substring(0, 2)
                                        '            If diff < 1 Then
                                        '                Exit Try
                                        '            End If

                                        '            oEdit = oForm.Items.Item("11").Specific
                                        '            Dim PetCode As String = oEdit.String

                                        '            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                        '            oRecordSet.DoQuery("SELECT T0.[U_AI_CustCode] FROM [dbo].[@AI_PETMASTER]  T0 WHERE T0.[U_PetCode] ='" & PetCode & "'")
                                        '            Dim CCode As String = oRecordSet.Fields.Item(0).Value
                                        '            oRecordSet = Nothing
                                        '            GC.Collect()
                                        '            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                        '            oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal] FROM OCRD T0 WHERE T0.[CardCode] ='" & CCode & "'")
                                        '            Dim NoDayPass As Integer = oRecordSet.Fields.Item(0).Value
                                        '            Dim DayPassUsed As Integer = oRecordSet.Fields.Item(1).Value
                                        '            Dim DayPassBal As Integer = oRecordSet.Fields.Item(2).Value
                                        '            Dim NewDayPassUsed As Integer = oRecordSet.Fields.Item(1).Value + 1
                                        '            Dim NewDayPassBal As Integer = NoDayPass - NewDayPassUsed
                                        '            oRecordSet = Nothing
                                        '            GC.Collect()
                                        '            oEdit = oForm.Items.Item("15").Specific
                                        '            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                        '            Dim s1 As String = "Update ocrd set U_AI_DayPassUsed=" & NewDayPassUsed & ",U_AI_DayPassBal=" & NewDayPassUsed & ",U_AI_TOTDP = " & NewDayPassBal & ",U_AI_LastVisit='" & oEdit.Value & "' WHERE CardCode ='" & CCode & "'"
                                        '            oRecordSet.DoQuery(s1)
                                        '            oRecordSet = Nothing
                                        '            GC.Collect()
                                        '            If NewDayPassBal < 0 Then
                                        '                SBO_Application.StatusBar.SetText("Negative Day Pass", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
                                        '                SBO_Application.MessageBox("Negative Day Pass using")
                                        '            End If
                                        '        Catch ex As Exception
                                        '        End Try
                                        '    End If
                                        'Catch ex As Exception
                                        '    SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        'End Try


                                    End If
                                End If
                        End Select
                    End If
                End If
            Catch ex As Exception
                'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            End Try

        Catch ex As Exception

        End Try
    End Sub
    Function ParamDate(ByVal dt As String) As Date
        Dim d, m, y As String
        Dim Z As Date
        d = dt.Substring(0, 2)
        m = dt.Substring(3, 2)
        y = dt.Substring(6, 2)
        'Z = CDate("May 25, 1986")
        Z = CDate(d & "/" & m & "/" & y)
        'Return System.DateTime.Parse(dt, format1, Globalization.DateTimeStyles.None)
        Return Z
    End Function
    Public Sub TansportUpdate(ByVal Pickup As String, ByVal Dropoff As String)
        Try
            oEdit = oForm.Items.Item("15").Specific
            Dim dt As String = oEdit.Value
            oEdit = oForm.Items.Item("11").Specific
            Dim BPCOde As String = OwnerCode(oEdit.String, Ocompany)
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            Dim st As String = "SELECT distinct T1.[U_AI_CustCode],T0.[U_AI_PetCode] FROM [dbo].[@AI_ATTENDANCE]  T0 left join[dbo].[@AI_PETMASTER]  T1 on  T1.[U_PetCode] = T0.[U_AI_PetCode] WHERE T1.[U_AI_CustCode] ='" & BPCOde & "' and  T0.[U_AI_Date] ='" & dt & "' and T0.[U_AI_Pickup]='Y'"
            oRecordSet.DoQuery(st)
            'MsgBox(oRecordSet.RecordCount)
            If oRecordSet.RecordCount <= 1 And Pickup = "Y" Then
                Pickup = "Y"
            Else
                Pickup = ""
            End If
            oRecordSet.DoQuery("SELECT distinct T1.[U_AI_CustCode],T0.[U_AI_PetCode] FROM [dbo].[@AI_ATTENDANCE]  T0 left join[dbo].[@AI_PETMASTER]  T1 on  T1.[U_PetCode] = T0.[U_AI_PetCode] WHERE T1.[U_AI_CustCode] ='" & BPCOde & "' and  T0.[U_AI_Date] ='" & dt & "' and T0.[U_AI_Dropoff]='Y'")
            If oRecordSet.RecordCount <= 1 And Dropoff = "Y" Then
                Dropoff = "Y"
            Else
                Dropoff = ""
            End If

            Dim count As Integer = 0
            If Pickup = "Y" And Dropoff = "Y" Then
                count = 2
            End If
            If Pickup = "Y" And Dropoff = "" Then
                count = 1
            End If
            If Pickup = "" And Dropoff = "Y" Then
                count = 1
            End If
            If count > 0 Then
                oEdit = oForm.Items.Item("11").Specific
                BPCOde = OwnerCode(oEdit.String, Ocompany)
                Dim NoTrans As Integer = 0
                Dim TransUsed As Integer = 0
                Dim AccNoTrans As Integer = 0
                Dim AccTransUsed As Integer = 0
                Dim newTransUsed As Integer = 0
                Dim NewTransBal As Integer = 0
                Dim NewAccTransUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoTrans], T0.[U_AI_TransUsed], T0.[U_AI_TransBal], T0.[U_AI_LastTrans], T0.[U_AI_AccumTrans], T0.[U_AI_AccumTransU] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoTrans = oRecordSet.Fields.Item(0).Value
                TransUsed = oRecordSet.Fields.Item(1).Value
                AccNoTrans = oRecordSet.Fields.Item(4).Value
                AccTransUsed = oRecordSet.Fields.Item(5).Value
                newTransUsed = TransUsed + count
                NewTransBal = NoTrans - newTransUsed
                NewAccTransUsed = AccTransUsed + count
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_TransBal=" & NewTransBal & ",U_AI_TransUsed=" & newTransUsed & ",U_AI_AccumTransU=" & NewAccTransUsed & " WHERE CardCode='" & BPCode & "' ")
                '===========
                If NewTransBal < 0 Then
                    Dim oODRF As SAPbobsCOM.Documents = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
                    oODRF.DocObjectCode = SAPbobsCOM.BoObjectTypes.oOrders
                    oODRF.CardCode = BPCode
                    oODRF.DocDate = Now.Date
                    oODRF.Lines.ItemCode = "BT1001"
                    oODRF.Lines.Quantity = 1
                    oODRF.Lines.Add()
                    Dim k As Integer
                    k = oODRF.Add()
                    Dim SerrorMsg As String = ""
                    Ocompany.GetLastError(k, SerrorMsg)
                    Dim i As Integer
                    If i <> 0 Then
                        ' SBO_Application.MessageBox(Ocompany.GetLastErrorDescription, Ocompany.GetLastErrorCode)
                        'Exit Sub
                    End If
                End If
                '===========
            End If

        Catch ex As Exception
        End Try
    End Sub
    Public Sub TansportUpdate_UpdateMode(ByVal Dropoff As String)
        Try
            Dim count As Integer = 0
            oItem = oForm.Items.Item("67")
            If oItem.Enabled = True Then
                If Dropoff = "Y" Then
                    count = 1
                End If
            End If
            If count > 0 Then
                oEdit = oForm.Items.Item("11").Specific
                Dim BPCode As String = OwnerCode(oEdit.String, Ocompany)
                Dim NoTrans As Integer = 0
                Dim TransUsed As Integer = 0
                Dim AccNoTrans As Integer = 0
                Dim AccTransUsed As Integer = 0
                Dim newTransUsed As Integer = 0
                Dim NewTransBal As Integer = 0
                Dim NewAccTransUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoTrans], T0.[U_AI_TransUsed], T0.[U_AI_TransBal], T0.[U_AI_LastTrans], T0.[U_AI_AccumTrans], T0.[U_AI_AccumTransU] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoTrans = oRecordSet.Fields.Item(0).Value
                TransUsed = oRecordSet.Fields.Item(1).Value
                AccNoTrans = oRecordSet.Fields.Item(4).Value
                AccTransUsed = oRecordSet.Fields.Item(5).Value
                newTransUsed = TransUsed + count
                NewTransBal = NoTrans - newTransUsed
                NewAccTransUsed = AccTransUsed + count
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_TransBal=" & NewTransBal & ",U_AI_TransUsed=" & newTransUsed & ",U_AI_AccumTransU=" & NewAccTransUsed & " WHERE CardCode='" & BPCode & "' ")
                '============
                If NewTransBal < 0 Then
                    Dim oODRF As SAPbobsCOM.Documents = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
                    oODRF.DocObjectCode = SAPbobsCOM.BoObjectTypes.oOrders
                    oODRF.CardCode = BPCode
                    oODRF.DocDate = Now.Date
                    oODRF.Lines.ItemCode = "BT1001"
                    oODRF.Lines.Quantity = 1
                    oODRF.Lines.Add()
                    Dim k As Integer
                    k = oODRF.Add()
                    Dim SerrorMsg As String = ""
                    Ocompany.GetLastError(k, SerrorMsg)
                    Dim i As Integer
                    If i <> 0 Then
                        ' SBO_Application.MessageBox(Ocompany.GetLastErrorDescription, Ocompany.GetLastErrorCode)
                        'Exit Sub
                    End If
                End If
                '===========
            End If
        Catch ex As Exception
        End Try
    End Sub
    Public Sub DayPassUpdate_UpdateMode()
        Try
            ' oMatrixUp.Columns.Item("1").Cells.Item(iCount + 1).Click(SAPbouiCOM.BoCellClickType.ct_Regular)
            'oEdit = oForm.Items.Item("11").Click(SAPbouiCOM.BoCellClickType.ct_Right)
            oEdit = oForm.Items.Item("11").Specific
            Dim BPCode As String = OwnerCode(oEdit.String, Ocompany)
            oEdit = oForm.Items.Item("11").Specific
            Dim PetSize As String = PSize(oEdit.String, Ocompany)

            If PetSize = "Small" Then

                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed - 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed - 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBal=" & NewDayPassBal & ",U_AI_DayPassUsed=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")



            ElseIf PetSize = "Medium" Then
                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassM], T0.[U_AI_DayPassUsedM], T0.[U_AI_DayPassBalM], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed - 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed - 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalM=" & NewDayPassBal & ",U_AI_DayPassUsedM=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")

            ElseIf PetSize = "Large" Then
                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassB], T0.[U_AI_DayPassUsedB], T0.[U_AI_DayPassBalB], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed - 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed - 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalB=" & NewDayPassBal & ",U_AI_DayPassUsedB=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")

            End If
        Catch ex As Exception
        End Try
    End Sub
    Public Sub DayPassUpdate()
        Try
            oEdit = oForm.Items.Item("11").Specific
            Dim BPCode As String = OwnerCode(oEdit.String, Ocompany)
            oEdit = oForm.Items.Item("11").Specific
            Dim PetSize As String = PSize(oEdit.String, Ocompany)

            If PetSize = "Small" Then

                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed + 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed + 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBal=" & NewDayPassBal & ",U_AI_DayPassUsed=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")
                ''============
                'If NewDayPassBal < 0 Then
                '    Dim oODRF As SAPbobsCOM.Documents = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
                '    oODRF.DocObjectCode = SAPbobsCOM.BoObjectTypes.oOrders
                '    oODRF.CardCode = BPCode
                '    oODRF.DocDate = Now.Date
                '    oODRF.Lines.ItemCode = "DP1001"
                '    oODRF.Lines.Quantity = 1
                '    oODRF.Lines.Add()
                '    Dim k As Integer
                '    k = oODRF.Add()
                '    Dim SerrorMsg As String = ""
                '    Ocompany.GetLastError(k, SerrorMsg)
                '    Dim i As Integer
                '    If i <> 0 Then
                '        ' SBO_Application.MessageBox(Ocompany.GetLastErrorDescription, Ocompany.GetLastErrorCode)
                '        'Exit Sub
                '    End If
                'End If
                ''===========

            ElseIf PetSize = "Medium" Then
                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassM], T0.[U_AI_DayPassUsedM], T0.[U_AI_DayPassBalM], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed + 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed + 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalM=" & NewDayPassBal & ",U_AI_DayPassUsedM=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")
                ''============
                'If NewDayPassBal < 0 Then
                '    Dim oODRF As SAPbobsCOM.Documents = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
                '    oODRF.DocObjectCode = SAPbobsCOM.BoObjectTypes.oOrders
                '    oODRF.CardCode = BPCode
                '    oODRF.DocDate = Now.Date
                '    oODRF.Lines.ItemCode = "DP1001"
                '    oODRF.Lines.Quantity = 1
                '    oODRF.Lines.Add()
                '    Dim k As Integer
                '    k = oODRF.Add()
                '    Dim SerrorMsg As String = ""
                '    Ocompany.GetLastError(k, SerrorMsg)
                '    Dim i As Integer
                '    If i <> 0 Then
                '        ' SBO_Application.MessageBox(Ocompany.GetLastErrorDescription, Ocompany.GetLastErrorCode)
                '        'Exit Sub
                '    End If
                'End If
                ''===========
            ElseIf PetSize = "Large" Then
                Dim NoDaypass As Integer = 0
                Dim DaypassUsed As Integer = 0
                Dim AccNoDaypass As Integer = 0
                Dim AccDaypassUsed As Integer = 0
                Dim newDayPassUsed As Integer = 0
                Dim NewDayPassBal As Integer = 0
                Dim NewAccDaypassUsed As Integer = 0
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassB], T0.[U_AI_DayPassUsedB], T0.[U_AI_DayPassBalB], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                NoDaypass = oRecordSet.Fields.Item(0).Value
                DaypassUsed = oRecordSet.Fields.Item(1).Value
                AccNoDaypass = oRecordSet.Fields.Item(4).Value
                AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                newDayPassUsed = DaypassUsed + 1
                NewDayPassBal = NoDaypass - newDayPassUsed
                NewAccDaypassUsed = AccDaypassUsed + 1
                oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalB=" & NewDayPassBal & ",U_AI_DayPassUsedB=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")
                ''============
                'If NewDayPassBal < 0 Then
                '    Dim oODRF As SAPbobsCOM.Documents = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
                '    oODRF.DocObjectCode = SAPbobsCOM.BoObjectTypes.oOrders
                '    oODRF.CardCode = BPCode
                '    oODRF.DocDate = Now.Date
                '    oODRF.Lines.ItemCode = "DP1001"
                '    oODRF.Lines.Quantity = 1
                '    oODRF.Lines.Add()
                '    Dim k As Integer
                '    k = oODRF.Add()
                '    Dim SerrorMsg As String = ""
                '    Ocompany.GetLastError(k, SerrorMsg)
                '    Dim i As Integer
                '    If i <> 0 Then
                '        ' SBO_Application.MessageBox(Ocompany.GetLastErrorDescription, Ocompany.GetLastErrorCode)
                '        'Exit Sub
                '    End If
                'End If
                ''===========
            End If
        Catch ex As Exception
        End Try
    End Sub
    Public Sub DayPassBalanceReport()
        oForm = SBO_Application.Forms.Item("DayPassBalanceReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDP As String = ""
        Dim TDP As String = ""
        Dim FCode As String = ""
        Dim TCode As String = ""
        Dim yr As String = ""
        oEdit = oForm.Items.Item("8").Specific
        If oEdit.String = "" Then
            FDP = -10000000
        Else
            FDP = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            TDP = 10000000
        Else
            TDP = oEdit.Value
        End If

        oEdit = oForm.Items.Item("12").Specific
        If oEdit.String = "" Then
            FCode = "%"
        Else
            FCode = oEdit.Value
        End If

        'oEdit = oForm.Items.Item("14").Specific
        'If oEdit.String = "" Then
        '    TCode = ""
        'Else
        '    TCode = oEdit.Value
        'End If

        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            'Sqlstr = "SELECT T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP],T0.[U_AI_LastVisit],T0.[CardCode], T0.[CardName], T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal], T1.[U_PetCode], T1.[U_PetName] FROM [dbo].[OCRD]  T0 RIGHT jOIN [dbo].[@AI_PETMASTER]  T1 ON  T1.[U_AI_CustCode] = T0.[CardCode] WHERE T0.[CardCode]  BETWEEN '" & FCode & "' AND '" & TCode & "' and  T0.[U_AI_DayPassBal]  between '" & FDP & "' and '" & TDP & "'  and  T1.[U_PetCode]  between '" & FPet & "' and '" & TPet & "' ORDER BY T0.[CardCode], T0.[CardName], T1.[U_PetCode], T1.[U_PetName]"
            Sqlstr = "SELECT T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP],T0.[U_AI_LastVisit],T0.[U_AI_ExpDate],T0.[CardCode], T0.[CardName], T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal],T0.[U_AI_NoDayPassM], T0.[U_AI_DayPassUsedM], T0.[U_AI_DayPassBalM], T0.[U_AI_NoDayPassB], T0.[U_AI_DayPassUsedB], T0.[U_AI_DayPassBalB],T0.[U_AI_PetDetail]  FROM [dbo].[OCRD]  T0 WHERE T0.[CardCode]  like '" & FCode & "'  and T0.[CardType]   ='C' and  ((isnull(T0.[U_AI_DayPassBal],0)  between '" & FDP & "' and '" & TDP & "') or (isnull(T0.[U_AI_DayPassBalM],0)  between '" & FDP & "' and '" & TDP & "')or (isnull(T0.[U_AI_DayPassBalB],0)  between '" & FDP & "' and '" & TDP & "'))  ORDER BY T0.[CardName],T0.[CardCode]"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.DayPass_Report(Sqlstr, Ocompany)
            frm.Text = "Day Pass Balance Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()

        Catch ex As Exception
        End Try
    End Sub
    Public Sub AnnualPackageReport()
        oForm = SBO_Application.Forms.Item("AnnualReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            FPet = "%"
        Else
            FPet = oEdit.String
        End If

        'oEdit = oForm.Items.Item("6").Specific
        'If oEdit.String = "" Then
        '    SBO_Application.StatusBar.SetText("Plz Enter To Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        '    BubbleEvent = False
        '    Exit Sub
        'End If
        'TPet = oEdit.String
        oEdit = oForm.Items.Item("8").Specific
        Dim yr As String
        If oEdit.String = "" Then
            yr = "2000"
            FDt = yr & "-01-01"
        Else
            FDt = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            yr = Now.Year.ToString
            TDt = yr & "-12-31"
        Else
            TDt = oEdit.Value
        End If
        oCombo = oForm.Items.Item("130").Specific



        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            If oCombo.Selected.Description = "1" Then
                Sqlstr = "SELECT T0.U_Date, T0.U_CCode, T0.U_CName, T0.U_Pet, T0.U_TotPassSmall, T0.U_UsedSmall, T0.U_BalanceSmall, T0.U_TotPassMedium, T0.U_UsedMedium, T0.U_BalanceMedium, T0.U_TotPassBig, T0.U_UsedBig, T0.U_BalanceBig FROM [dbo].[@AI_ANNUAL]  T0 WHERE ( T0.[U_CCode]  like '" & FPet & "' and  T0.[U_Date]  between '" & FDt & "' and '" & TDt & "') and  (  T0.[U_BalanceSmall] < 0  or  T0.[U_BalanceMedium] <0 or  T0.[U_BalanceBig] <0 )"
            Else
                Sqlstr = "SELECT T0.U_Date, T0.U_CCode, T0.U_CName, T0.U_Pet, T0.U_TotPassSmall, T0.U_UsedSmall, T0.U_BalanceSmall, T0.U_TotPassMedium, T0.U_UsedMedium, T0.U_BalanceMedium, T0.U_TotPassBig, T0.U_UsedBig, T0.U_BalanceBig FROM [dbo].[@AI_ANNUAL]  T0 WHERE T0.[U_CCode]  like '" & FPet & "' and  T0.[U_Date]  between '" & FDt & "' and '" & TDt & "'"
            End If

            Dim frm As MY_Report
            frm = New MY_Report
            frm.AnnualPack_Report(Sqlstr, Ocompany)
            frm.Text = "Annual Package Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()

        Catch ex As Exception
        End Try
    End Sub
    Public Sub AttendanceReport()
        oForm = SBO_Application.Forms.Item("AttendanceReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            FPet = "%"
        Else
            FPet = oEdit.String
        End If

        'oEdit = oForm.Items.Item("6").Specific
        'If oEdit.String = "" Then
        '    SBO_Application.StatusBar.SetText("Plz Enter To Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        '    BubbleEvent = False
        '    Exit Sub
        'End If
        'TPet = oEdit.String
        oEdit = oForm.Items.Item("8").Specific
        Dim yr As String
        If oEdit.String = "" Then
            yr = "2000"
            FDt = yr & "-01-01"
        Else
            FDt = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            yr = Now.Year.ToString
            TDt = yr & "-12-31"
        Else
            TDt = oEdit.Value
        End If


        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "SELECT T0.[U_BagID], T0.[U_StorageID], T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_Date], T0.[U_AI_TimeIn], T0.[U_AI_TimeOut], T0.[U_AI_LockerNo], T0.[U_AI_Comments] FROM [dbo].[@AI_ATTENDANCE]  T0 WHERE T0.[U_AI_PetCode] like '" & FPet & "'  and T0.[U_AI_Date]  between '" & FDt & "' and '" & TDt & "' order by T0.[U_AI_Date],T0.[U_AI_PetName]"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.Attendance_Report(Sqlstr, Ocompany)
            frm.Text = "Attendance Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()

        Catch ex As Exception
        End Try
    End Sub
    Public Sub LastAttendance()
        oForm = SBO_Application.Forms.Item("LastAttendanceReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            FPet = "%"
        Else
            FPet = oEdit.String
        End If

        'oEdit = oForm.Items.Item("6").Specific
        'If oEdit.String = "" Then
        '    SBO_Application.StatusBar.SetText("Plz Enter To Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        '    BubbleEvent = False
        '    Exit Sub
        'End If
        'TPet = oEdit.String
        oEdit = oForm.Items.Item("8").Specific
        Dim yr As String
        If oEdit.String = "" Then
            yr = "2000"
            FDt = yr & "-01-01"
        Else
            FDt = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            yr = Now.Year.ToString
            TDt = yr & "-12-31"
        Else
            TDt = oEdit.Value
        End If


        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "declare @tb table(petcode nvarchar(100),Fromdate date, todate date,a int) " & _
"insert into @tb " & _
"select U_AI_PetCode,max(U_AI_Date), null, MAX(docentry) from [@AI_ATTENDANCE] T0 group by U_AI_PetCode " & _
"update T0 set todate=T1.Tdate " & _
"from @tb T0 join ( select U_AI_PetCode,max(U_AI_Date) Tdate from [@AI_ATTENDANCE] T0 " & _
"join @tb T1 on T0.U_AI_PetCode=T1.petcode and T0.DocEntry<>T1.a " & _
"group by U_AI_PetCode) T1 on T0.petcode=T1.U_AI_PetCode " & _
"select petcode,(select U_PetName from [@AI_PETMASTER] where U_PetCode=petcode) as 'PetName',isnull(Fromdate,'') as 'AttDate',todate as 'LastAttDate',isnull(DATEDIFF(dd,todate,Fromdate),'') as 'DateDiffer' from @tb where Fromdate between '" & FDt & "' and '" & TDt & "' and petcode like '" & FPet & "' order by PetName"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.Last_Attendance_Report(Sqlstr, Ocompany)
            frm.Text = "Last Attendance Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()

        Catch ex As Exception
        End Try
    End Sub
    Public Sub DogInventory_Report()
        oForm = SBO_Application.Forms.Item("DogInventoryReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDt As String = ""
        Dim TDt As String = ""
        'Dim Bag As String = ""
        'Dim Leash As String = ""
        'Dim Book As String = ""
        'Dim Toy As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            FPet = "%"
        Else
            FPet = oEdit.String
        End If

        oEdit = oForm.Items.Item("8").Specific
        Dim yr As String
        If oEdit.String = "" Then
            yr = "2000"
            FDt = yr & "-01-01"
        Else
            FDt = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            yr = Now.Year.ToString
            TDt = yr & "-12-31"
        Else
            TDt = oEdit.Value
        End If
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "SELECT T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_Date], T0.[U_AI_TimeIn], T0.[U_AI_TimeOut], T0.[U_AI_InvBag], T0.[U_AI_InvLeash], T0.[U_AI_InvBook], T0.[U_AI_InvToy], T0.[U_AI_InvOther], T0.[U_AI_LockerNo], T0.[U_BagID], T0.[U_StorageID] FROM [dbo].[@AI_ATTENDANCE]  T0 WHERE T0.[U_AI_PetCode]  like '" & FPet & "' and  T0.[U_AI_Date]  between '" & FDt & "' and '" & TDt & "'  ORDER BY T0.[U_AI_Date],T0.[U_AI_PetName],T0.[DocNum]"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.DogInv_Report(Sqlstr, Ocompany)
            frm.Text = "Dog Inventory Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
        'If (pVal.MenuUID = "1282") And pVal.BeforeAction = False And pVal.InnerEvent = False Then
        '    Try
        '        If oForm.UniqueID = "AI_ATTENDANCE" Then
        '            oItem = oForm.Items.Item("102")
        '            oItem.Enabled = True
        '            oItem = oForm.Items.Item("66")
        '            oItem.Enabled = True
        '            oItem = oForm.Items.Item("68")
        '            oItem.Enabled = True
        '            oItem = oForm.Items.Item("67")
        '            oItem.Enabled = True
        '            oItem = oForm.Items.Item("69")
        '            oItem.Enabled = True
        '        End If
        '    Catch ex As Exception

        '    End Try
        'End If
        If (pVal.MenuUID = "1288" Or pVal.MenuUID = "1289" Or pVal.MenuUID = "1290" Or pVal.MenuUID = "1291") And pVal.BeforeAction = False And pVal.InnerEvent = False Then
            Try
                If oForm.UniqueID = "AI_ATTENDANCE" Then
                    oItem = oForm.Items.Item("102")
                    oChk1 = oForm.Items.Item("102").Specific
                    If oChk1.Checked = True Then
                        oItem.Enabled = False
                    Else
                        oItem.Enabled = True
                    End If
                    oItem = oForm.Items.Item("66")
                    oChk1 = oForm.Items.Item("66").Specific
                    If oChk1.Checked = True Then
                        oItem.Enabled = False
                    Else
                        oItem.Enabled = True
                    End If
                    oItem = oForm.Items.Item("67")
                    oChk1 = oForm.Items.Item("67").Specific
                    If oChk1.Checked = True Then
                        oItem.Enabled = False
                    Else
                        oItem.Enabled = True
                    End If
                    oItem = oForm.Items.Item("68")
                    oChk1 = oForm.Items.Item("68").Specific
                    If oChk1.Checked = True Then
                        oItem.Enabled = False
                    Else
                        oItem.Enabled = True
                    End If
                    oItem = oForm.Items.Item("69")
                    oChk1 = oForm.Items.Item("69").Specific
                    If oChk1.Checked = True Then
                        oItem.Enabled = False
                    Else
                        oItem.Enabled = True
                    End If
                End If
            Catch ex As Exception
            End Try
        End If
        If (pVal.MenuUID = "1282" Or pVal.MenuUID = "1281") And pVal.BeforeAction = True And pVal.InnerEvent = False Then
            Try
                If oForm.UniqueID = "AI_ATTENDANCE" Then
                    oItem = oForm.Items.Item("102")
                    oItem.Enabled = True
                    oItem = oForm.Items.Item("66")
                    oItem.Enabled = True
                    oItem = oForm.Items.Item("67")
                    oItem.Enabled = True
                    oItem = oForm.Items.Item("68")
                    oItem.Enabled = True
                    oItem = oForm.Items.Item("69")
                    oItem.Enabled = True
                End If
            Catch ex As Exception
            End Try
        End If

        If pVal.MenuUID = "1283" And pVal.BeforeAction = True And pVal.InnerEvent = False Then
            oForm = SBO_Application.Forms.ActiveForm
            If oForm.UniqueID = "AI_ATTENDANCE" Then
                Try

                    oForm = SBO_Application.Forms.Item("AI_ATTENDANCE")
                    oEdit = oForm.Items.Item("11").Specific
                    'oCheck = oForm.Items.Item("69").Specific
                    Dim CheckOut As Boolean = False
                    'If oCheck.Checked = True Then
                    '    CheckOut = True
                    'End If
                    'oCheck = oForm.Items.Item("67").Specific
                    'If oCheck.Checked = True Then
                    CheckOut = True
                    ' End If
                    oChk1 = oForm.Items.Item("102").Specific
                    If oChk1.Checked = True Then
                        CheckOut = False
                    End If
                    If CheckOut = True Then
                        Dim BPCode As String = OwnerCode(oEdit.String, Ocompany)
                        Dim Size As String = PSize(oEdit.String, Ocompany)
                        If Size = "Small" Then
                            Dim NoDaypass As Integer = 0
                            Dim DaypassUsed As Integer = 0
                            Dim AccNoDaypass As Integer = 0
                            Dim AccDaypassUsed As Integer = 0
                            Dim newDayPassUsed As Integer = 0
                            Dim NewDayPassBal As Integer = 0
                            Dim NewAccDaypassUsed As Integer = 0
                            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPass], T0.[U_AI_DayPassUsed], T0.[U_AI_DayPassBal], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                            NoDaypass = oRecordSet.Fields.Item(0).Value
                            DaypassUsed = oRecordSet.Fields.Item(1).Value
                            AccNoDaypass = oRecordSet.Fields.Item(4).Value
                            AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                            newDayPassUsed = DaypassUsed - 1
                            NewDayPassBal = NoDaypass - newDayPassUsed
                            NewAccDaypassUsed = AccDaypassUsed - 1
                            oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBal=" & NewDayPassBal & ",U_AI_DayPassUsed=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")

                        ElseIf Size = "Medium" Then
                            Dim NoDaypass As Integer = 0
                            Dim DaypassUsed As Integer = 0
                            Dim AccNoDaypass As Integer = 0
                            Dim AccDaypassUsed As Integer = 0
                            Dim newDayPassUsed As Integer = 0
                            Dim NewDayPassBal As Integer = 0
                            Dim NewAccDaypassUsed As Integer = 0
                            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassM], T0.[U_AI_DayPassUsedM], T0.[U_AI_DayPassBalM], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                            NoDaypass = oRecordSet.Fields.Item(0).Value
                            DaypassUsed = oRecordSet.Fields.Item(1).Value
                            AccNoDaypass = oRecordSet.Fields.Item(4).Value
                            AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                            newDayPassUsed = DaypassUsed - 1
                            NewDayPassBal = NoDaypass - newDayPassUsed
                            NewAccDaypassUsed = AccDaypassUsed - 1
                            oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalM=" & NewDayPassBal & ",U_AI_DayPassUsedM=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")
                        ElseIf Size = "Large" Then
                            Dim NoDaypass As Integer = 0
                            Dim DaypassUsed As Integer = 0
                            Dim AccNoDaypass As Integer = 0
                            Dim AccDaypassUsed As Integer = 0
                            Dim newDayPassUsed As Integer = 0
                            Dim NewDayPassBal As Integer = 0
                            Dim NewAccDaypassUsed As Integer = 0
                            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet.DoQuery("SELECT T0.[U_AI_NoDayPassB], T0.[U_AI_DayPassUsedB], T0.[U_AI_DayPassBalB], T0.[U_AI_LastVisit], T0.[U_AI_ACCDAYPASS], T0.[U_AI_TOTDP] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                            NoDaypass = oRecordSet.Fields.Item(0).Value
                            DaypassUsed = oRecordSet.Fields.Item(1).Value
                            AccNoDaypass = oRecordSet.Fields.Item(4).Value
                            AccDaypassUsed = oRecordSet.Fields.Item(5).Value
                            newDayPassUsed = DaypassUsed - 1
                            NewDayPassBal = NoDaypass - newDayPassUsed
                            NewAccDaypassUsed = AccDaypassUsed - 1
                            oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                            oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_DayPassBalB=" & NewDayPassBal & ",U_AI_DayPassUsedB=" & newDayPassUsed & ",U_AI_TOTDP=" & NewAccDaypassUsed & " WHERE CardCode='" & BPCode & "' ")
                            '============
                        End If
                    End If
                Catch ex As Exception
                End Try
                Try

                    Dim PickUp As String = ""
                    Dim Dropoff As String = ""
                    oCheck = oForm.Items.Item("66").Specific
                    If oCheck.Checked = True Then
                        PickUp = "Y"
                    End If
                    ' oCheck = oForm.Items.Item("68").Specific
                    oCheck = oForm.Items.Item("67").Specific
                    If oCheck.Checked = True Then
                        Dropoff = "Y"
                    End If
                    Dim count As Integer = 0
                    If PickUp = "Y" And Dropoff = "Y" Then
                        count = -2
                    End If
                    If PickUp = "Y" And Dropoff = "" Then
                        count = -1
                    End If
                    If PickUp = "" And Dropoff = "Y" Then
                        count = -1
                    End If
                    If count <> 0 Then
                        oEdit = oForm.Items.Item("11").Specific
                        Dim BPCode As String = OwnerCode(oEdit.String, Ocompany)
                        Dim NoTrans As Integer = 0
                        Dim TransUsed As Integer = 0
                        Dim AccNoTrans As Integer = 0
                        Dim AccTransUsed As Integer = 0
                        Dim newTransUsed As Integer = 0
                        Dim NewTransBal As Integer = 0
                        Dim NewAccTransUsed As Integer = 0
                        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                        oRecordSet.DoQuery("SELECT T0.[U_AI_NoTrans], T0.[U_AI_TransUsed], T0.[U_AI_TransBal], T0.[U_AI_LastTrans], T0.[U_AI_AccumTrans], T0.[U_AI_AccumTransU] FROM OCRD T0 WHERE T0.[CardCode]  ='" & BPCode & "'")
                        NoTrans = oRecordSet.Fields.Item(0).Value
                        TransUsed = oRecordSet.Fields.Item(1).Value
                        AccNoTrans = oRecordSet.Fields.Item(4).Value
                        AccTransUsed = oRecordSet.Fields.Item(5).Value
                        newTransUsed = TransUsed + count
                        NewTransBal = NoTrans - newTransUsed
                        NewAccTransUsed = AccTransUsed + count
                        oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                        oRecordSet1.DoQuery("UPDATE OCRD SET U_AI_TransBal=" & NewTransBal & ",U_AI_TransUsed=" & newTransUsed & ",U_AI_AccumTransU=" & NewAccTransUsed & " WHERE CardCode='" & BPCode & "' ")
                    End If
                Catch ex As Exception

                End Try
            End If
        End If
    End Sub
End Class
